import pdfplumber

path = 'MySQL常用命令大全.pdf'
with pdfplumber.open(path) as pdf:
    # [<Page:1>, <Page:2>, <Page:3>, <Page:4>, <Page:5>, <Page:6>, <Page:7>, <Page:8>, <Page:9>, <Page:10>, <Page:11>, <Page:12>]
    # print(pdf.pages)
    # print(len(pdf.pages))
    # 获取第一页文档内容
    # page =  pdf.pages[0]
    content = ''
    for index in range(len(pdf.pages)):
        page = pdf.pages[index]
        # page.extract_text()函数即读取文本内容，下面这步是去掉文档最下面的页码
        page_content = '\n'.join(page.extract_text().split('\n')[:-1])
        # print(page_content)
        content += page_content
    print(content)